<template>
    <div>
      <html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:fmt="http://www.w3.org/1999/xhtml">
      <div>
          <Top/>
      </div>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../css/jpetstore.css" type="text/css">
</head>
<body>
<div th:replace="common/top"/>


<div id="Content">

    <div id="BackLink">
        <a th:href="@{/catalog/viewProduct(productId=${item.product.productId})}"
           th:text="'Return to '+${item.product.name}">Return to Product</a>
    </div>

    <div id="Catalog">

        <table>
            <tr>
                <td th:utext="${item.product.description}"><img src="../../assets/catalog/images/fish3.gif" />Fresh Water fish from Japan</td>
            </tr>
            <tr>
                <td>
                    <b th:text="${item.itemId}">{{newitem.itemId}}</b>
                </td>
            </tr>
            <tr>
                <td>
                    <b th:utext="${item.attribute1}+${item.product.name}">
                        <font size="4">
                            {{newitem.productId}}
                        </font>
                    </b>
                </td>
            </tr>
            <tr>
                <td th:utext="${item.product.name}">{{newitem.productName}}</td>
            </tr>
            <tr>
                <td th:if="${item.quantity} <=0">Back Order</td>
                
            </tr>
            <tr>
                <td>  <fmt:formatNumber th:text="${item.listPrice}" pattern="$#,##0.00"/>
                    {{newitem.listPrice}}
                </td>
            </tr>

            <tr>
                <td>
                    <a @click="submitForm('ruleForm')">
                        Add to Cart
                    </a>
                        
                </td>
            </tr>
        </table>

    </div>


</div>


<div th:replace="common/bottom"/>
</body>
 <div>
          <Bottom/>
      </div>
</html>
    </div>
</template>
<style scoped>

</style>
<script>
import Top from '../../common/top'
import Bottom from '../../common/bottom'

export default {
    name: "category",
    data() {
        return {
            status:"0",
            newitem:[],
            ruleForm: {
          username : localStorage.getItem("token"),
          browseitemid : this.$route.params.ItemId,
        }
        }
    },
    
    created () {
        console.log("hhhh")
        console.log(this.ruleForm.username)
        const _this = this
        //这句话将route中的参数传递到category中
         var itemid = this.$route.params.ItemId
         console.log(itemid)
         var url_item = "http://localhost:8081/catalog/products/items/"+itemid
         console.log(url_item)
        axios.get(url_item).then(function(resp){
            console.log(resp)
              _this.newitem = resp.data.data
              _this.ruleForm.browseitemid = resp.data.data.itemid
          })  
          console.log("fwe")
          console.log(this.ruleForm.browseitemid)
          console.log("fwe")
    },
     components: {
         Bottom,
        Top
    },


    methods: {
      submitForm(formName) {
          const _this = this;
       
            console.log(_this.ruleForm)
            var str= this.$route.params.ItemId
            str = str.replace("\"", "");
          this.ruleForm.browseitemid = str
            alert('添加购物车成功!');
            axios.post('http://localhost:8081/account/saveCart',this.ruleForm).then(function(resp){
                console.log(_this.ruleForm)
            })
          }
    },
     
    }
    



</script>